package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.BrandCategoryAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.PictureAddNewDTO;
import cn.tedu.csmall.product.service.IBrandCategoryService;
import cn.tedu.csmall.product.service.IPictureService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 处理图片相关请求的控制器
 *
 * @author java@tedu.cn
 * @version 0.0.1
 */
@Api(tags = "07图片管理模块")

@Slf4j
@RestController
@RequestMapping("/pictures")
public class PictureController {

    @Autowired
    private IPictureService iPictureService;

    public PictureController() {
        log.debug("创建控制器对象：PictureController");
    }

    @ApiOperation("添加图片")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid PictureAddNewDTO pictureAddNewDTO) {
        log.debug("开始处理【添加】的请求，参数：{}", pictureAddNewDTO);
        iPictureService.addNew(pictureAddNewDTO);
        log.debug("添加图片成功！");
        return JsonResult.ok();
    }

    @ApiOperation("根据id删除图片")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@Range(min = 1, message = "删除相册失败，尝试删除的相册的ID无效！")
                                   @PathVariable Long id) {
        log.debug("开始处理【根据id删除相册】的请求，参数：{}", id);
        iPictureService.deleteById(id);
        return JsonResult.ok();
    }




}
